package com.jsb.laundry.controller;

import com.alibaba.fastjson.JSONObject;
import com.jsb.laundry.common.constant.CommonConstants;
import com.jsb.laundry.common.design_service.pay.enums.PayModeEnum;
import com.jsb.laundry.common.design_service.pay.properties.WechatMiniPayProperties;
import com.jsb.laundry.common.enums.Lottery;
import com.jsb.laundry.common.enums.OrderStatus;
import com.jsb.laundry.common.enums.ProductType;
import com.jsb.laundry.common.utils.JSBUtil;
import com.jsb.laundry.common.utils.redis.RedisUtil;
import com.jsb.laundry.dao.ActivityDao;
import com.jsb.laundry.dao.CouponDao;
import com.jsb.laundry.dao.OrderDao;
import com.jsb.laundry.model.entity.*;
import com.jsb.laundry.service.OrderService;
import com.wechat.pay.contrib.apache.httpclient.util.AesUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 第三方回调入口
 */
@RestController
@RequestMapping("/jsbUserCallBack")
public class PayCallBackController extends BaseController {

    private static final Logger LOGGER = LoggerFactory.getLogger(PayCallBackController.class);

    @Resource
    private WechatMiniPayProperties wechatMiniPayProperties;

    @Resource
    private OrderDao orderDao;
    @Resource
    private CouponDao couponDao;

    @Resource
    private OrderService orderService;

    @Resource
    private ActivityDao activityDao;

    @Resource
    private RedisUtil redisUtil;


    /**
     * 解密回调返回内容
     *
     * @return
     * @throws Exception
     */
    private String parseCallback(String data) throws Exception {
        // 解析回调中内容
        LOGGER.info("-------支付结果解析:" + data);
        JSONObject json = JSONObject.parseObject(data);
        String ciphertext = json.getJSONObject("resource").getString("ciphertext");
        final String associated_data = json.getJSONObject("resource").getString("associated_data");
        final String nonce = json.getJSONObject("resource").getString("nonce");
        AesUtil aesUtil = new AesUtil(wechatMiniPayProperties.getApiV3Key().getBytes());
        ciphertext = aesUtil.decryptToString(associated_data.getBytes(), nonce.getBytes(), ciphertext);
        return ciphertext;
    }


    /**
     * 便民洗衣支付成功回调(购物车、普通活动回调)
     * 参考文档：https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_5.shtml
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/paymentNotice/laundryCallbackUrlCartOrActivity")
    public void PaymentCallback1(HttpServletRequest request, HttpServletResponse response) throws Exception {
        // 解析回调中内容  支付结果
        String reqParams = JSBUtil.read(request.getInputStream());
        LOGGER.info("微信支付成功返回原数据:{}", reqParams);
        JSONObject json = JSONObject.parseObject(reqParams);

        //TODO 解密回调返回内容(验签) 支付信息
        String ciphertext = parseCallback(reqParams);
        //支付成功返回的json
        JSONObject payResult = JSONObject.parseObject(ciphertext);

        String orderId = payResult.getString("out_trade_no"); //订单id
        String outTradeNo = payResult.getString("transaction_id"); //微信方订单号
        String productType = payResult.getString("attach");//额外携带数据，聚洗衣商品类型...

        JsbOrders orderInfo = orderDao.getOrderInfo(orderId);
        if (orderInfo != null && !OrderStatus.WAIT_PAY.getCode().equals(orderInfo.getOrderStatus())) {
            //成功
            response.setStatus(200);
            response.getWriter().write("{\"code\": \"SUCCESS\",\"message\": \"OK\"}");
            return;
        }

        String openId = payResult.getJSONObject("payer").getString("openid");
        Integer total = payResult.getJSONObject("amount").getInteger("payer_total"); //用户实际支付金额
        UserInfo userInfo = orderDao.findUserInfo(orderInfo.getUserId()); //用户id

        /**
         *  成功后,处理业务
         */
        if (json.getString("event_type").equals("TRANSACTION.SUCCESS")) {
            //资金入公司账户
            fundIntoCompanyAccount("http://127.0.0.1:20000/riderOrder/system/orderPaySplitting", orderId, total);

            //用户支付后，若是被骑手邀请进入的，就给骑手分佣
            giveRiderCommission(orderId, userInfo.getUserId(), "1");
            //抽奖邀请人人加次数
            orderDao.updUserLotteryNum(userInfo.getUserId(), Lottery.buyGoods.getNum());//抽奖邀请人加次数
            orderDao.addUserLotteryRecordRoad(userInfo.getUserId(), Lottery.buyGoods.getMsg(), Lottery.buyGoods.getCode(), Lottery.buyGoods.getNum());//获得途径
            //支付成功删除redis待支付订单
            redisUtil.deleteObject(CommonConstants.TIMEOUT30_WAIT_PAY_ORDER + orderId);

            //获取订单信息
            JsbOrders parentOrder = orderDao.getOrderInfo(orderId);
            JsbOrdersShippingAddresses userAddress = orderDao.getUserAddress(orderId);
            List<JsbOrdersItem> subOrderList = orderDao.getSubOrderList(orderId);
            parentOrder.setUserAddress(userAddress);
            parentOrder.setSubOrderList(subOrderList);


            if (ProductType.CART.name().equals(productType) || ProductType.ACTIVITY.name().equals(productType)) { //正常下的订单支付\活动支付
                //更新父订单状态 jsb_orders
                int var0 = orderService.updParentOrderInfo(parentOrder);
                //更新订单付款明细 jsb_orders_transactions
                JsbOrdersTransactions ordersTransactions = new JsbOrdersTransactions();
                ordersTransactions.setOrderId(orderId).setBatchNo(outTradeNo).setPaymentType(PayModeEnum.JSB_USER_WECHAT_MINI_PAY.name())
                        .setCaptureAccount(PayModeEnum.JSB_USER_WECHAT_MINI_PAY.getMsg());
                orderDao.updOrdersTransactions(ordersTransactions);

                String voucherId = parentOrder.getVoucherId();
                if (!JSBUtil.isEmptyString(voucherId)) { //使用了优惠券
                    orderDao.updUseCouponRecord(parentOrder.getUserId(), voucherId);
                }

            }

            /**
             * 通知
             */
            paymentNoticeUser(openId, orderId);
            paymentNoticeRider(orderId);
            /**
             * 订单状态日志
             */
            addOrderStatusLog(orderId, OrderStatus.SUCCESS_PAY, OrderStatus.ORDER_DIRECTION1.getMsg());
        }

        //成功
        response.setStatus(200);
        response.getWriter().write("{\"code\": \"SUCCESS\",\"message\": \"OK\"}");
    }


    /**
     * 月卡 298 398 回调
     * 参考文档：https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_5.shtml
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/paymentNotice/laundryCallbackUrlMonthCard")
    public void PaymentCallback2(HttpServletRequest request, HttpServletResponse response) throws Exception {
        // 解析回调中内容  支付结果
        String reqParams = JSBUtil.read(request.getInputStream());
        LOGGER.info("微信支付成功返回原数据:{}", reqParams);
        JSONObject json = JSONObject.parseObject(reqParams);

        //TODO 解密回调返回内容(验签) 支付信息
        String ciphertext = parseCallback(reqParams);
        //支付成功返回的json
        JSONObject payResult = JSONObject.parseObject(ciphertext);

        String orderId = payResult.getString("out_trade_no"); //订单id
        String outTradeNo = payResult.getString("transaction_id"); //微信方订单号
        String productType = payResult.getString("attach");//额外携带数据，聚洗衣商品类型...

        //支付状态
        MonthCard monthCard = orderDao.getMonthCardOrderInfo(orderId);
        if (monthCard != null && monthCard.getPayTime() != null) {//成功
            response.setStatus(200);
            response.getWriter().write("{\"code\": \"SUCCESS\",\"message\": \"OK\"}");
            return;
        }

        String openId = payResult.getJSONObject("payer").getString("openid");
        Integer total = payResult.getJSONObject("amount").getInteger("payer_total"); //用户实际支付金额
        UserInfo userInfo = orderDao.findUserInfo(monthCard.getUserId()); //用户id

        /**
         *  成功后,处理业务
         */
        if (json.getString("event_type").equals("TRANSACTION.SUCCESS")) {
            //资金入公司账户
            fundIntoCompanyAccount("http://127.0.0.1:20000/riderOrder/system/OrderPaySplitting", orderId, total);

            //用户支付后，若是被骑手邀请进入的，就给骑手分佣
            giveRiderCommission(orderId, userInfo.getUserId(), "2");
            //抽奖邀请人人加次数
            orderDao.updUserLotteryNum(userInfo.getUserId(), Lottery.buyGoods.getNum());//抽奖邀请人加次数
            orderDao.addUserLotteryRecordRoad(userInfo.getUserId(), Lottery.buyGoods.getMsg(), Lottery.buyGoods.getCode(), Lottery.buyGoods.getNum());//获得途径
            //支付成功删除redis待支付订单
            redisUtil.deleteObject(CommonConstants.TIMEOUT30_WAIT_PAY_ORDER + orderId);

            if (ProductType.MONTH_CART.name().equals(productType)) { //月卡活动购买(298|398)
                updMonthCard(orderId);
            }

            /**
             * 通知
             */
//            paymentNoticeUser(openId, orderId);

        }


        //成功
        response.setStatus(200);
        response.getWriter().write("{\"code\": \"SUCCESS\",\"message\": \"OK\"}");
    }


    /**
     * vip 回调
     * 参考文档：https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_5.shtml
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/paymentNotice/laundryCallbackUrlVip")
    public void PaymentCallback3(HttpServletRequest request, HttpServletResponse response) throws Exception {
        // 解析回调中内容  支付结果
        String reqParams = JSBUtil.read(request.getInputStream());
        LOGGER.info("微信支付成功返回原数据:{}", reqParams);
        JSONObject json = JSONObject.parseObject(reqParams);

        //TODO 解密回调返回内容(验签) 支付信息
        String ciphertext = parseCallback(reqParams);
        //支付成功返回的json
        JSONObject payResult = JSONObject.parseObject(ciphertext);

        String orderId = payResult.getString("out_trade_no"); //订单id
        String outTradeNo = payResult.getString("transaction_id"); //微信方订单号
        String productType = payResult.getString("attach");//额外携带数据，聚洗衣商品类型...

        //支付状态
        CouponUserBuyRecord  couponUserBuyRecord = orderDao.getVipOrderInfo(orderId);
        if (couponUserBuyRecord!=null && couponUserBuyRecord.getPayTime() != null) {//成功
            response.setStatus(200);
            response.getWriter().write("{\"code\": \"SUCCESS\",\"message\": \"OK\"}");
            return;
        }

        String openId = payResult.getJSONObject("payer").getString("openid");
        Integer total = payResult.getJSONObject("amount").getInteger("payer_total"); //用户实际支付金额
        UserInfo userInfo = orderDao.findUserInfo(couponUserBuyRecord.getUserId()); //用户id

        /**
         *  成功后,处理业务
         */
        if (json.getString("event_type").equals("TRANSACTION.SUCCESS")) {
            //资金入公司账户
            fundIntoCompanyAccount("http://127.0.0.1:20000/riderOrder/system/orderUserRecharge", orderId, total);

            //用户支付后，若是被骑手邀请进入的，就给骑手分佣
            giveRiderCommission(orderId, userInfo.getUserId(), "2");
            //抽奖邀请人人加次数
            orderDao.updUserLotteryNum(userInfo.getUserId(), Lottery.buyVip.getNum());//抽奖邀请人加次数
            orderDao.addUserLotteryRecordRoad(userInfo.getUserId(), Lottery.buyVip.getMsg(), Lottery.buyVip.getCode(), Lottery.buyVip.getNum());//获得途径

            //支付成功删除redis待支付订单
            redisUtil.deleteObject(CommonConstants.TIMEOUT30_WAIT_PAY_ORDER + orderId);

            if (ProductType.VIP_BUY.name().equals(productType)) { //优惠券VIP

                updVip(userInfo.getUserId(), orderId);

            }

            /**
             * 通知
             */
//            paymentNoticeUser(openId, orderId);

        }

        //成功
        response.setStatus(200);
        response.getWriter().write("{\"code\": \"SUCCESS\",\"message\": \"OK\"}");
    }


    /**
     * 校服 回调
     * 参考文档：https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_5.shtml
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/paymentNotice/laundryCallbackUrlSchool")
    public void PaymentCallback4(HttpServletRequest request, HttpServletResponse response) throws Exception {
        // 解析回调中内容  支付结果
        String reqParams = JSBUtil.read(request.getInputStream());
        LOGGER.info("微信支付成功返回原数据:{}", reqParams);
        JSONObject json = JSONObject.parseObject(reqParams);

        //TODO 解密回调返回内容(验签) 支付信息
        String ciphertext = parseCallback(reqParams);
        //支付成功返回的json
        JSONObject payResult = JSONObject.parseObject(ciphertext);

        String orderId = payResult.getString("out_trade_no"); //订单id
        String outTradeNo = payResult.getString("transaction_id"); //微信方订单号
        String productType = payResult.getString("attach");//额外携带数据，聚洗衣商品类型...

        SchoolRecord orderInfoStatus = orderDao.getSchoolOrderInfo(orderId);
        if (orderInfoStatus!=null && orderInfoStatus.getPayTime() != null) { //成功
            response.setStatus(200);
            response.getWriter().write("{\"code\": \"SUCCESS\",\"message\": \"OK\"}");
            return;
        }

        String openId = payResult.getJSONObject("payer").getString("openid");
        Integer total = payResult.getJSONObject("amount").getInteger("payer_total"); //用户实际支付金额
        UserInfo userInfo = orderDao.findUserInfo(orderInfoStatus.getUserId()); //用户id

        /**
         *  成功后,处理业务
         */
        if (json.getString("event_type").equals("TRANSACTION.SUCCESS")) {
            //资金入公司账户
            fundIntoCompanyAccount("http://127.0.0.1:20000/riderOrder/system/orderPaySplitting", orderId, total);

            //用户支付后，若是被骑手邀请进入的，就给骑手分佣
            giveRiderCommission(orderId, userInfo.getUserId(), "2");
            //抽奖邀请人人加次数
            orderDao.updUserLotteryNum(userInfo.getUserId(), Lottery.buyGoods.getNum());//抽奖邀请人加次数
            orderDao.addUserLotteryRecordRoad(userInfo.getUserId(), Lottery.buyGoods.getMsg(), Lottery.buyGoods.getCode(), Lottery.buyGoods.getNum());//获得途径
            //支付成功删除redis待支付订单
            redisUtil.deleteObject(CommonConstants.TIMEOUT30_WAIT_PAY_ORDER + orderId);

            //获取订单信息
            JsbOrders parentOrder = orderDao.getOrderInfo(orderId);
            JsbOrdersShippingAddresses userAddress = orderDao.getUserAddress(orderId);
            List<JsbOrdersItem> subOrderList = orderDao.getSubOrderList(orderId);
            parentOrder.setUserAddress(userAddress);
            parentOrder.setSubOrderList(subOrderList);

            if (ProductType.SCHOOL_MONTH.name().equals(productType)) { //校服包月
                updSchool(userInfo.getUserId(), orderId);
                //更新父订单状态 jsb_orders
                int var0 = orderService.updParentOrderInfo(parentOrder);
                //更新订单付款明细 jsb_orders_transactions
                JsbOrdersTransactions ordersTransactions = new JsbOrdersTransactions();
                ordersTransactions.setOrderId(orderId).setBatchNo(outTradeNo).setPaymentType(PayModeEnum.JSB_USER_WECHAT_MINI_PAY.name())
                        .setCaptureAccount(PayModeEnum.JSB_USER_WECHAT_MINI_PAY.getMsg());
                orderDao.updOrdersTransactions(ordersTransactions);

                String voucherId = parentOrder.getVoucherId();
                if (!JSBUtil.isEmptyString(voucherId)) { //使用了优惠券
                    orderDao.updUseCouponRecord(parentOrder.getUserId(), voucherId);
                }

                /**
                 * 通知
                 */
//                paymentNoticeUser(openId, orderId);
//                paymentNoticeRider(orderId);

            }

        }

        //成功
        response.setStatus(200);
        response.getWriter().write("{\"code\": \"SUCCESS\",\"message\": \"OK\"}");
    }


    /**
     * 备份 回调
     * 参考文档：https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_5.shtml
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/paymentNotice/PaymentCallbackBack")
    public void PaymentCallbackBack(HttpServletRequest request, HttpServletResponse response) throws Exception {
//        // 解析回调中内容  支付结果
//        String reqParams = JSBUtil.read(request.getInputStream());
//        LOGGER.info("微信支付成功返回原数据:{}", reqParams);
//        JSONObject json = JSONObject.parseObject(reqParams);
//
//        //TODO 解密回调返回内容(验签) 支付信息
//        String ciphertext = parseCallback(reqParams);
//        //支付成功返回的json
//        JSONObject payResult = JSONObject.parseObject(ciphertext);
//
//        String orderId = payResult.getString("out_trade_no"); //订单id
//        String outTradeNo = payResult.getString("out_trade_no"); //微信方订单号
//        String productType1 = payResult.getString("attach");//额外携带数据，聚洗衣商品类型...
//
//        JsbOrders orderInfo = orderDao.getOrderInfo(orderId);
//        if (orderInfo != null && !OrderStatus.WAIT_PAY.getCode().equals(orderInfo.getOrderStatus())) {
//            //成功
//            response.setStatus(200);
//            response.getWriter().write("{\"code\": \"SUCCESS\",\"message\": \"OK\"}");
//            return;
//        }
//
//        JSONObject jsonObject = JSONObject.parseObject(productType1);
//        String productType = jsonObject.getString("productType");
//        String openId = payResult.getJSONObject("payer").getString("openid");
//        Integer total = payResult.getJSONObject("amount").getInteger("payer_total"); //用户实际支付金额
//        UserInfo userInfo = orderDao.findUserInfo(openId); //用户id
//
//        /**
//         *  成功后,处理业务
//         */
//        if (json.getString("event_type").equals("TRANSACTION.SUCCESS")) {
//            //资金入公司账户
//            Map map = new HashMap();
//            map.put("orderId", orderId);
//            map.put("money", total);
//            HttpUtil.sendPost("http://127.0.0.1:20000/riderOrder/system/OrderPaySplitting", null, JSONObject.toJSONString(map));
//
//            //支付成功删除redis待支付订单
//            redisUtil.deleteObject(CommonConstants.TIMEOUT30_WAIT_PAY_ORDER + orderId);
//
//            //获取订单信息
//            JsbOrders parentOrder = orderDao.getOrderInfo(orderId);
//            JsbOrdersShippingAddresses userAddress = orderDao.getUserAddress(orderId);
//            List<JsbOrdersItem> subOrderList = orderDao.getSubOrderList(orderId);
//            parentOrder.setUserAddress(userAddress);
//            parentOrder.setSubOrderList(subOrderList);
//
//
//            if (ProductType.CART.name().equals(productType) || ProductType.ACTIVITY.name().equals(productType)) { //正常下的订单支付\活动支付
//                //更新父订单状态 jsb_orders
//                int var0 = orderService.updParentOrderInfo(parentOrder);
//                //更新订单付款明细 jsb_orders_transactions
//                JsbOrdersTransactions ordersTransactions = new JsbOrdersTransactions();
//                ordersTransactions.setOrderId(orderId).setBatchNo(outTradeNo).setPaymentType(PayModeEnum.JSB_USER_WECHAT_MINI_PAY.name())
//                        .setCaptureAccount(PayModeEnum.JSB_USER_WECHAT_MINI_PAY.getMsg());
//                orderDao.updOrdersTransactions(ordersTransactions);
//
//                String voucherId = parentOrder.getVoucherId();
//                if (!JSBUtil.isEmptyString(voucherId)) { //使用了优惠券
//                    orderDao.updUseCouponRecord(parentOrder.getUserId(), voucherId);
//                }
//
//            } else if (ProductType.VIP_BUY.name().equals(productType)) { //优惠券VIP
//
//                updVip(userInfo.getUserId(), orderId);
//
//            } else if (ProductType.SCHOOL_MONTH.name().equals(productType)) { //校服包月
//                updSchool(userInfo.getUserId(), orderId);
//                //更新父订单状态 jsb_orders
//                int var0 = orderService.updParentOrderInfo(parentOrder);
//                //更新订单付款明细 jsb_orders_transactions
//                JsbOrdersTransactions ordersTransactions = new JsbOrdersTransactions();
//                ordersTransactions.setOrderId(orderId).setBatchNo(outTradeNo).setPaymentType(PayModeEnum.JSB_USER_WECHAT_MINI_PAY.name())
//                        .setCaptureAccount(PayModeEnum.JSB_USER_WECHAT_MINI_PAY.getMsg());
//                orderDao.updOrdersTransactions(ordersTransactions);
//
//                String voucherId = parentOrder.getVoucherId();
//                if (!JSBUtil.isEmptyString(voucherId)) { //使用了优惠券
//                    orderDao.updUseCouponRecord(parentOrder.getUserId(), voucherId);
//                }
//
//            } else if (ProductType.MONTH_CART.name().equals(productType)) { //月卡活动购买(298|398)
//                updMonthCard(orderId);
//            } else if (ProductType.DIFF.name().equals(productType)) { // 补差价支付
//
//            }
//
//        }
//
//        //成功
//        response.setStatus(200);
//        response.getWriter().write("{\"code\": \"SUCCESS\",\"message\": \"OK\"}");
    }


    private void updSchool(String userId, String orderId) {
        activityDao.updSchoolDeal(userId, orderId);
    }


    /**
     * 修改月卡支付状态
     */
    private void updMonthCard(String orderId) {
        // 修改月卡支付状态
        activityDao.updMonthCardStatus(orderId);

    }


    /**
     * 支付成功改变优惠券(vip)订单状态
     */
    private void updVip(String userId, String orderId) {
        //TODO 支付成功改变优惠券订单状态
        int var2 = couponDao.updCouponRecord(userId, orderId);
        int var21 = couponDao.updCouponUserBuy(userId, orderId);

        //查看用户购买的套餐
        String userBuyCouponTcId = couponDao.getUserBuyCouponTc(orderId);


//        if ("tc1".equals(userBuyCouponTcId)) { //购买的是套餐1 (100元,奖励9.8元)
//            int currentBonus = 980;
//
//            //给用户账号余额 user_amount_details表 user_other_money=600元，只给1次
//            int userOtherMoney = 60000;
//            int var0 = couponDao.updUserAccountOtherMoney(userId, userOtherMoney);
//            //2.0奖励 capital_account表 frozen_amount=600元，只给1次 冻结资金
//            int var1 = couponDao.updCapitalAccount(userId, userOtherMoney);
//            LOGGER.info("VIP支付成功，用户：【{}】,订单id:【{}】", userId, orderId);
//            int white = orderDao.updateWhite(userId);//购买vip加入白名单
//        }


//        /**
//         *  查看是否被邀请,如果是被邀请进来的,给邀请人奖励
//         */
//        Promotion promotionId = couponDao.getPromotion(userId);//获取邀请人id、是否给过奖励
//
//        /**
//         * 如果有邀请人并且没有给过邀请人奖励
//         */
//        if (promotionId != null && !JSBUtil.isEmptyString(promotionId.getAppUserId()) && "0".equals(promotionId.getGiveAppUserReward())) {
//            //给邀请人奖励
//            int currentBonus = 0;
//            if ("tc1".equals(userBuyCouponTcId)) { //购买的是套餐1 (100元,奖励9.8元)
//                currentBonus = 980;
//
//                //给用户账号余额 user_amount_details表 user_other_money=600元，只给1次
//                int userOtherMoney = 60000;
//                int var0 = couponDao.updUserAccountOtherMoney(userId, userOtherMoney);
//                //2.0奖励 capital_account表 frozen_amount=600元，只给1次 冻结资金
//                int var1  = couponDao.updCapitalAccount(userId, userOtherMoney);
//
//            }
////            else if ("tc2".equals(userBuyCouponTcId)) {//购买的是套餐2 (20元,奖励1.8元)
////                currentBonus = 180;
////            }
//
//            /**
//             * 1.给邀请人奖励(用户购买了优惠券套餐 => 9.8元|1.8元 ) user_amount_details
//             */
//            couponDao.updUserAccountInfo(promotionId.getAppUserId(), currentBonus);
//            /**
//             * 2.添加金额奖励流水记录user_stream_record（当前奖励 9.8元|1.8元）
//             */
//            String streamId = "stream-" + JSBUtil.generateUUID();
//            couponDao.addUserStreamRecord(streamId, promotionId.getAppUserId(), currentBonus);
//
//            //改变promotion状态为给过奖励
//            promotionId.setUserId(userId);
//            int var23 = couponDao.updPromotion(promotionId);
//        }

    }


}